<template>
	<view style="backgorund:#ddd;">
		<image style="width:100%;" mode="scaleToFill"
			src="https://yjb.zjic.com.cn/minio/zhongjbx/temp/微信图片_20211018132604_1634534782057.jpg"></image>
		<div class="bg-white clearfix">
			<uni-row>
				<uni-col :span="12">
					<div class="margin20L">
						<button type="primary" size="default" class="btn-red margin15L margin10R"
							open-type="share">分享给好友</button>
					</div>
				</uni-col>
				<uni-col :span="12">
					<div class="margin20R">
						<button type="primary" size="default" class="btn-red margin15R margin10L"
							@click="shengchb">获取我的二维码</button>
					</div>
				</uni-col>
			</uni-row>
		</div>
		<uni-card class="font-bold" title="分享领钱规则" :isShadow="true">
			<uni-steps active-color="#f83d38" :options="[{title: '分享给好友'}, {title: '好友付款出单'}, {title: '系统转账佣金'}]"
				:active="2"></uni-steps>
			<div class="clear h10"></div>
			<p class="font-normal line-height-25">
				点击上方<span class="font-blue font-bold">"分享给好友"</span> 按钮，可以转发给好友或微信群。点击您分享链接进入小程序的人自动成为您的团队队员。
				点击上方<span class="font-blue font-bold"> "获取我的二维码"</span> 按钮，会下载一张您的专属二维码图片。把图片发到朋友圈，识别二维码进入的好用也会成为您的队员。
				队员下单付款出单后。系统会自动给您发放<span class="font-bold font-orange">300</span>元佣金到您的微信余额中。
				每单<span class="font-bold font-orange">300</span>元，推荐更多好友拿更多奖励，没有上限。
			</p>
		</uni-card>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				fenxtp: [],
			}
		},
		onLoad() {
			let that = this
			
			uni.request({
				url: getApp().globalData.serviceUrl + "/sys/dictItem/list",
				data: {
					dictId: "1453640158131376129",
				},
				dataType: 'json',
				method: 'GET',
				success: (result) => {
					if (result.data.success) {
						that.fenxtp = result.data.result.records
					}
				}
			});
		},
		
		methods: {
			downloadFile(url) {
				uni.authorize({
					scope: 'scope.writePhotosAlbum',
					success() {
						uni.downloadFile({
							url: url,
							success: (res) => {
								if (res.statusCode === 200) {
									console.log('下载成功');
									uni.saveImageToPhotosAlbum({
										filePath: res.tempFilePath,
										success: function() {
											console.log('save success');
											uni.showToast({
												title: "已保存到相册"
											})
										},
										fail: function() {
											console.error(res)
										}
				
									});
								}
							},
							fail: (error) => {
								log.error(error)
							}
						})
				
					}, 
					fail(error) {
						uni.showModal({
						    title: '提示',
						    content: '是否打开授权界面',
						    success: function (res) {
						        if (res.confirm) {
						            console.log('用户点击确定');
									uni.openSetting({
									  success(res) {
									    console.log(res.authSetting)
									  }
									});
						        } else if (res.cancel) {
						            console.log('用户点击取消');
						        }
						    }
						});
						
					}
				})
			},
			
			shengchb() {
				let that = this
				uni.request({
					url: getApp().globalData.serviceUrl + "/weixin/getUnlimited2Minio",
					data: {
						mobile: uni.getStorageSync("userInfo").phone
					},
					dataType: 'json',
					method: 'GET',
					success: (result) => {
						if (result.data.success) {
							that.downloadFile(result.data.result)
						}
					}
				});
			},

			onShareAppMessage() {
				let openId = "";
				if (uni.getStorageSync("openId") != null)
					openId = uni.getStorageSync("openId").openid

				return {
					title: "分享领钱",
					path: 'pages/home/home?shareBy=' + openId,
					imageUrl: this.fenxtp[0].itemValue
				}
			},

		}
	}
</script>

<style scoped>
	page {
		background: #ddd !important;
	}
</style>
